# coding: utf-8
class PagesController < ApplicationController

  # 关于本站
  def all
  	@page_title ||= '关于本站 - 逗死了' if(request.url.include? '/about')
  	@page_title ||= '版权声明 - 逗死了' if(request.url.include? '/copyright')
  	@page_title ||= '网站地图 - 逗死了' if(request.url.include? '/sitemap')
    render :template => 'pages/all.html.erb'
  end

  # GET: 用户反馈
  def feedback
    @page_title = '用户反馈 - 逗死了'
    render :template => 'pages/feedback.html.erb'
  end

  # GET：sitemap
  def sitemap
    xml = '<?xml version="1.0" encoding="UTF-8"?>'
    xml << '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
    xml << ' xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"'
    xml << ' xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
    xml << '<url>'
    xml << '<loc>http://www.dousile.com/</loc>'
    xml << '<changefreq>daily</changefreq>'
    xml << '<priority>0.9</priority>'
    xml << '</url>'

    # 主路径
    arr = [];
    arr << 'http://www.dousile.com/xiao/'
    arr << 'http://www.dousile.com/leng/'
    arr << 'http://www.dousile.com/chengren/'
    arr << 'http://www.dousile.com/tupian/'
    arr << 'http://www.dousile.com/shipin/'
    arr.each do |url|
      xml << '<url>'
      xml << '<loc>%s</loc>' % url
      xml << '<priority>0.8</priority>'
      xml << '</url>'
    end

    # 文档共享
    posts = Post.where("postdate <= '#{Time.now.in_time_zone().strftime('%Y-%m-%d %H:%M:%S')}'").order('postdate DESC')
    posts.each do |post|
      xml << '<url>'
      xml << '<loc>http://www.dousile.com/detail/%s.html</loc>' % [ post.id ]
      xml << '<priority>0.7</priority>'
      xml << '<lastmod>%s</lastmod>' % post.postdate.in_time_zone(+8.hours).strftime('%Y-%m-%dT%H:%M:%S+08:00')
      xml << '</url>'
    end
    xml << '</urlset>'
    render :xml => xml
  end

end
